/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Points;


/**
 *
 * @author @author Avishai Kopeliansky
 * 
 **/
public class PointContainer  {
Point [] Arr ;
final int size = 10;
final int resizer = 10;
int items, speindex;


/**
 * Default Constructor
 */
public PointContainer(){
    Arr = new Point [size];
    items = 0 ;
    speindex=0;
}

/**
 * Copy Constructor
 * @param p Point Container
 */
public PointContainer(PointContainer p){
    Arr = new Point [p.size()];
    for(int i=0 ; i < Arr.length ; i++){
        Arr[i]= new Point(p.elementAt(i));
    }
    this.items = p.items ;

}

/**
 * Adding a point to the Container
 * @param P
 */
public void add( Point P){
        //Checking if container is full , if so then resizing it.
      if(items == Arr.length){
      Resize();
      }
     
      Arr[items++]=new Point (P);
      
}

/**
 * Returns the point in the given index , used to move the data from the PointContainer to Array List
 * @param index
 * @return null or Arr[index]
 */
public Point elementAt(int index){
    if(index >= 0 && index < Arr.length)
    return Arr[index];
    else
        return null;
}
//Resizing the Container
private void Resize(){
    Point [] Temp = new Point [Arr.length+resizer];
    for(int i=0 ; i  < Arr.length ; i++){
        Temp[i] = Arr[i];
    }

    Arr=Temp;
}

/**
 * is the container empty?
 * @return true || false
 */
public boolean isEmpty(){
    return items==0;
}

/**
 * @param temp Point to check
 * @return true if is inside,false if not in range
 * 
 */
public boolean isInside(Point temp){
      for(int i=0 ; i < items ; i++){
       if(Arr[i].GetX() == temp.GetX() && Arr[i].GetY() == temp.GetY())
       {
           speindex =i;
           return true;
       }
    }
    return false;
}

/**
 * @param temp Point to find and remove
 */
public void remove(Point temp)
{
    if(items >  0 )
    {
       if( this.isInside(temp)){
        if(speindex == items){
            items--;
        }
        else{
                for(int i=speindex ; i < items-1 ; i++)
              {
                    this.Arr[i] = this.Arr[i+1];
              }
                items--;
        }
        }
    }

}
/**
 * Return the actual size of the container
 * @return this.items
 */
public int size(){return this.items;}

/**
 * Returns the Maximum size of the container
 * @return Arr.length
 */
public int capacity(){return this.Arr.length;}


}
